home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / ww_tv.exe / SYSTEM.H < prev    next >
C/C++ Source or Header  |  1992-08-21  |  8KB  |  408 lines

  1. /* ------------------------------------------------------------------------*/
  2. /*                                                                         */
  3. /*   SYSTEM.H                                                              */
  4. /*                                                                         */
  5. /*   Copyright (c) Borland International 1991                              */
  6. /*   All Rights Reserved.                                                  */
  7. /*                                                                         */
  8. /*   defines the classes THWMouse, TMouse, TEventQueue, TDisplay,          */
  9. /*   TScreen, and TSystemError                                             */
  10. /*                                                                         */
  11. /* ------------------------------------------------------------------------*/
  12.  
  13. // Primatech Modification History:
  14. //
  15. //      11-14-91 JLS    Added shiftState to the TEvent structure
  16. //
  17. //      07-05-92 JLS    Synced with TV1.03 (BC3.10)
  18. //
  19.  
  20. #pragma option -Vo-
  21. #if defined( __BCOPT__ ) && __BCPLUSPLUS__ > 0x0300
  22. #pragma option -po-
  23. #endif
  24.  
  25. #if !defined( __EVENT_CODES )
  26. #define __EVENT_CODES
  27.  
  28. /* Event codes */
  29.  
  30. const evMouseDown = 0x0001;
  31. const evMouseUp   = 0x0002;
  32. const evMouseMove = 0x0004;
  33. const evMouseAuto = 0x0008;
  34. const evKeyDown   = 0x0010;
  35. const evCommand   = 0x0100;
  36. const evBroadcast = 0x0200;
  37.  
  38. /* Event masks */
  39.  
  40. const evNothing   = 0x0000;
  41. const evMouse     = 0x000f;
  42. const evKeyboard  = 0x0010;
  43. const evMessage   = 0xFF00;
  44.  
  45. /* Mouse button state masks */
  46.  
  47. const mbLeftButton  = 0x01;
  48. const mbRightButton = 0x02;
  49.  
  50. #endif  // __EVENT_CODES
  51.  
  52.  
  53. #if defined( Uses_TEvent ) && !defined( __TEvent )
  54. #define __TEvent
  55.  
  56. struct MouseEventType
  57. {
  58.     uchar buttons;
  59.     Boolean doubleClick;
  60.     TPoint where;
  61. };
  62.  
  63. class THWMouse
  64. {
  65.  
  66. protected:
  67.  
  68.     THWMouse();
  69.     THWMouse( const THWMouse& ) {};
  70.     ~THWMouse();
  71.  
  72.     static void show();
  73.     static void hide();
  74.  
  75.     static void setRange( ushort, ushort );
  76.     static void getEvent( MouseEventType& );
  77.     static void registerHandler( unsigned, void (far *)() );
  78.     static Boolean present();
  79.  
  80.     static void suspend();
  81.     static void resume();
  82.     static void inhibit();
  83.  
  84. protected:
  85.  
  86.     static uchar near buttonCount;
  87.  
  88. private:
  89.  
  90.     static Boolean near handlerInstalled;
  91.     static Boolean near noMouse;
  92.  
  93. };
  94.  
  95. inline Boolean THWMouse::present()
  96. {
  97.     return Boolean( buttonCount != 0 );
  98. }
  99.  
  100. inline void THWMouse::inhibit()
  101. {
  102.     noMouse = True;
  103. }
  104.  
  105. class TMouse : public THWMouse
  106. {
  107.  
  108. public:
  109.  
  110.     TMouse();
  111.     ~TMouse();
  112.  
  113.     static void show();
  114.     static void hide();
  115.  
  116.     static void setRange( ushort, ushort );
  117.  
  118.     static void getEvent( MouseEventType& );
  119.     static void registerHandler( unsigned, void (far *)() );
  120.     static Boolean present();
  121.  
  122.     static void suspend() { THWMouse::suspend(); }
  123.     static void resume() { THWMouse::resume(); show(); }
  124.  
  125. };
  126.  
  127. inline void TMouse::show()
  128. {
  129.     THWMouse::show();
  130. }
  131.  
  132. inline void TMouse::hide()
  133. {
  134.     THWMouse::hide();
  135. }
  136.  
  137. inline void TMouse::setRange( ushort rx, ushort ry )
  138. {
  139.     THWMouse::setRange( rx, ry );
  140. }
  141.  
  142. inline void TMouse::getEvent( MouseEventType& me )
  143. {
  144.     THWMouse::getEvent( me );
  145. }
  146.  
  147. inline void TMouse::registerHandler( unsigned mask, void (far *func)() )
  148. {
  149.     THWMouse::registerHandler( mask, func );
  150. }
  151.  
  152. inline Boolean TMouse::present()
  153. {
  154.     return THWMouse::present();
  155. }
  156.  
  157. struct CharScanType
  158. {
  159.     uchar charCode;
  160.     uchar scanCode;
  161. };
  162.  
  163. struct KeyDownEvent
  164. {
  165.     union
  166.         {
  167.         ushort keyCode;
  168.         CharScanType charScan;
  169.         };
  170. };
  171.  
  172. struct MessageEvent
  173. {
  174.     ushort command;
  175.     union
  176.         {
  177.         void *infoPtr;
  178.         long infoLong;
  179.         ushort infoWord;
  180.         short infoInt;
  181.         uchar infoByte;
  182.         char infoChar;
  183.         };
  184. };
  185.  
  186. struct TEvent
  187. {
  188.     ushort what;
  189.     union
  190.     {
  191.         MouseEventType mouse;
  192.         KeyDownEvent keyDown;
  193.         MessageEvent message;
  194.     };
  195.     uchar shiftState;
  196.  
  197.     TEvent() : shiftState(0) {}
  198.     TEvent(int what_) : what(what_),shiftState(0) {}
  199.     void getMouseEvent();
  200.     void getKeyEvent();
  201. };
  202.  
  203. #endif  // Uses_TEvent
  204.  
  205. #if defined( Uses_TEventQueue ) && !defined( __TEventQueue )
  206. #define __TEventQueue
  207.  
  208. class TEventQueue
  209. {
  210. public:
  211.     TEventQueue();
  212.     ~TEventQueue();
  213.  
  214.     static void getMouseEvent( TEvent& );
  215.     static void suspend();
  216.     static void resume();
  217.  
  218.     friend class TView;
  219.     friend void genRefs();
  220.     friend class TProgram;
  221.     static ushort near doubleDelay;
  222.     static Boolean near mouseReverse;
  223.  
  224. private:
  225.  
  226.     static TMouse near mouse;
  227.     static void getMouseState( TEvent& );
  228.     static void huge mouseInt();
  229.  
  230.     static void setLast( TEvent& );
  231.  
  232.     static MouseEventType near lastMouse;
  233.     static MouseEventType near curMouse;
  234.  
  235.     static MouseEventType near downMouse;
  236.     static ushort near downTicks;
  237.  
  238.     static ushort far * near Ticks;
  239.     static TEvent near eventQueue[ eventQSize ];
  240.     static TEvent * near eventQHead;
  241.     static TEvent * near eventQTail;
  242.     static Boolean near mouseIntFlag;
  243.     static ushort near eventCount;
  244.  
  245.     static Boolean near mouseEvents;
  246.  
  247.     static ushort near repeatDelay;
  248.     static ushort near autoTicks;
  249.     static ushort near autoDelay;
  250.  
  251. };
  252.  
  253. inline void TEvent::getMouseEvent()
  254. {
  255.     TEventQueue::getMouseEvent( *this );
  256. }
  257.  
  258. #endif  // Uses_TEventQueue
  259.  
  260. #if defined( Uses_TScreen ) && !defined( __TScreen )
  261. #define __TScreen
  262.  
  263. #ifdef PROTECT
  264.  
  265. extern ushort monoSeg;
  266. extern ushort colrSeg;
  267. extern ushort biosSeg;
  268.  
  269. #endif
  270.  
  271. class TDisplay
  272. {
  273.  
  274. public:
  275.  
  276.     friend class TView;
  277.  
  278.     enum videoModes
  279.         {
  280.         smBW80      = 0x0002,
  281.         smCO80      = 0x0003,
  282.         smMono      = 0x0007,
  283.         smFont8x8   = 0x0100
  284.         };
  285.  
  286.     static void clearScreen( uchar, uchar );
  287.  
  288.     static void setCursorType( ushort );
  289.     static ushort getCursorType();
  290.  
  291.     static ushort getRows();
  292.     static ushort getCols();
  293.  
  294.     static void setCrtMode( ushort );
  295.     static ushort getCrtMode();
  296.  
  297. protected:
  298.  
  299.     TDisplay() { updateIntlChars(); };
  300.     TDisplay( const TDisplay& ) { updateIntlChars(); };
  301.     ~TDisplay() {};
  302.  
  303. private:
  304.  
  305.     static void videoInt();
  306.     static void updateIntlChars();
  307.  
  308.     static ushort far * near equipment;
  309.     static uchar far * near crtInfo;
  310.     static uchar far * near crtRows;
  311.  
  312. };
  313.  
  314. class TScreen : public TDisplay
  315. {
  316.  
  317. public:
  318.  
  319.     TScreen();
  320.     ~TScreen();
  321.  
  322.     static void setVideoMode( ushort mode );
  323.     static void clearScreen();
  324.  
  325.     static ushort near startupMode;
  326.     static ushort near startupCursor;
  327.     static ushort near screenMode;
  328.     static uchar near screenWidth;
  329.     static uchar near screenHeight;
  330.     static Boolean near hiResScreen;
  331.     static Boolean near checkSnow;
  332.     static uchar far * near screenBuffer;
  333.     static ushort near cursorLines;
  334.  
  335.     static void setCrtData();
  336.     static ushort fixCrtMode( ushort );
  337.  
  338.     static void suspend();
  339.     static void resume();
  340.  
  341. };
  342.  
  343. #endif  // Uses_TScreen
  344.  
  345. #if defined( Uses_TSystemError ) && !defined( __TSystemError )
  346. #define __TSystemError
  347.  
  348. class far TDrawBuffer;
  349.  
  350. class TSystemError
  351. {
  352.  
  353. public:
  354.  
  355.     TSystemError();
  356.     ~TSystemError();
  357.  
  358.     static Boolean near ctrlBreakHit;
  359.  
  360.     static void suspend();
  361.     static void resume();
  362.     static void setSysErrorFunc(short ( far *func)(short, uchar )) {sysErrorFunc = func;}
  363.     static short ( far *sysErrorFunc )( short, uchar );
  364.  
  365. private:
  366.  
  367.     static ushort near sysColorAttr;
  368.     static ushort near sysMonoAttr;
  369.     static Boolean near saveCtrlBreak;
  370.     static Boolean near sysErrActive;
  371.  
  372.     static void swapStatusLine( TDrawBuffer far & );
  373.     static ushort selectKey();
  374.     static short sysErr( short, uchar );
  375.  
  376.     static Boolean near inIDE;
  377.  
  378.     static const char *const near errorString[14];
  379.     static const char * near sRetryOrCancel;
  380.  
  381.     friend class Int11trap;
  382.  
  383. };
  384.  
  385. class Int11trap
  386. {
  387.  
  388. public:
  389.